﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.Services.Client;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Regions;

namespace Product_1.Views
{
    /// <summary>
    /// Interaction logic for Product_1_View.xaml
    /// </summary>
    public partial class Product_1_View : UserControl, IProduct_1_View
    {
        ServiceReference1.Container context = new ServiceReference1.Container(new Uri("http://localhost:1179/odata"));

        private readonly IUnityContainer container;
        private readonly IRegionManager rManager;

        public event EventHandler lotnumberResult = delegate { };

        private IproductPresenter _presenter;

        string IProduct_1_View.LotNumber
        {
            get
            {
                return LotNumber.SelectedItem.ToString();
            }
        }

        public Product_1_View(IUnityContainer c, IRegionManager r)
        {
            InitializeComponent();

            container = c;
            rManager = r;


            this.BacchusListView.ItemsSource = (IEnumerable)context.Bacchus;
           
            this.materialsDataGrid.DataContext = from kkk in context.Materials
                                                 where kkk.Pro_Id == 1
                                                 select kkk;
            this.materialsDataGrid2.DataContext =
                                                from kkk in context.Materials
                                                where kkk.Pro_Id != 1
                                                select kkk;




            this.LotNumber.ItemsSource = context.Product_Mid
                                         .Where(kkk => kkk.Pro_Id == 1)
                                         //.Where(kkk => kkk.PM_LotNumber == kkk.PM_LotNumber.)


            //.GroupBy(kkk => kkk.PM_LotNumber)
                                          .Select(kkk => kkk);

            //from kkk in context.Product_Mid
            //where kkk.Pro_Id == 1

            //select new
            //{
                
            //};
                                         
            //from kkk in 

            //where kkk.Pro_Id == 1
            //select kkk;
            //select new
            //{
            //    PM_LotNumber = kkk.PM_LotNumber
            //};




        }

        public Product_1_View(IproductPresenter presenter) : this()
        {
            _presenter = presenter;
            _presenter.View = this;
        }



        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.bacchusDataGrid.DataContext = from kkk in context.Bacchus
                                               select new
                                               {
                                                   
                                                   Bac_Name = kkk.Bac_Name,
                                                   Bac_Quantity = kkk.Bac_Quantity * (Convert.ToInt32(this.Product_Quantity.Text))
                                               };
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            Uri viewNav = new Uri("Product_2_View", UriKind.Relative);
            rManager.RequestNavigate(RegionNames.MainContentRegion, viewNav);


            //this.materialsDataGrid.DataContext = from kkk in context.Materials
            //                                     where kkk.Pro_Id == 1
            //                                     select new
            //                                     {
            //                                         Mat_Name = kkk.Mat_Name,
            //                                         Mat_Quantity = kkk.Mat_Quantity
            //                                                                       - (kkk.Bac_Quantity * (Convert.ToInt32(this.Product_Quantity.Text)))
            //                                     };



            //var sss = from kkk in context.Product_Mid
            //          where kkk.Pro_Id == 1
            //          select new
            //          {
            //              PM_Date = kkk.PM_Date,
            //              PM_LotNumber = this.LotNumber.Text,
            //              PM_QC = kkk.PM_QC,
            //              PM_State = kkk.PM_State

            //          };


        }
    }
}
